package service.impl;

import dao.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pojo.User;
import service.UserService;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 用户表业务逻辑实现类
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User findUserById(Integer id) {
        return userMapper.findUserById(id);
    }

    @Override
    public User findUserByUsername(String username) {
        return userMapper.findUserByUsername(username);
    }

    @Override
    public List<User> findAllUsers() {
        return userMapper.findAllUsers();
    }

    @Override
    public int addUser(User user) {
        // 自动填充默认值
        if (user.getIsLocked() == null) {
            user.setIsLocked(true); // 默认启用用户
        }
        // 不设置createTime，使用数据库默认值
        return userMapper.addUser(user);
    }

    @Override
    public int updateUser(User user) {
        return userMapper.updateUser(user);
    }

    @Override
    public int deleteUser(Integer id) {
        return userMapper.deleteUser(id);
    }

    @Override
    public int lockUser(Integer id, Boolean isLocked) {
        return userMapper.lockUser(id, isLocked);
    }
}